# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.sessions.models import Session

# Create your models here.

# show 是否可见
# ctime 创建时间
# mtime 修改时间

class Brand(models.Model):
	"""品牌"""
	name = models.CharField(max_length=50)
	logo = models.CharField(max_length=1024)
	url = models.CharField(max_length=1024)
	show = models.BooleanField(default=True)
	ctime = models.DateTimeField(auto_now_add=True)
	mtime = models.DateTimeField(auto_now=True)

class Shelf(models.Model):
	"""产品分类"""
	name = models.CharField(max_length=50)
	self_id = models.IntegerField()
	parent_shelf = models.IntegerField()
	order = models.IntegerField()
	show = models.BooleanField(default=True)
	ctime = models.DateTimeField(auto_now_add=True)
	mtime = models.DateTimeField(auto_now=True)

class Product(models.Model):
	"""产品信息"""
	pid = models.CharField(max_length=50)
	name = models.CharField(max_length=200)
	brand = models.ForeignKey(Brand)
	shelf = models.ForeignKey(Shelf)
	purchase_price = models.CharField(max_length=10)
	zlbaobao_price = models.CharField(max_length=10)
	original_price = models.CharField(max_length=10)
	attribute_json = models.CharField(max_length=512)
	information = models.TextField()
	show = models.BooleanField(default=True)
	ctime = models.DateTimeField(auto_now_add=True)
	mtime = models.DateTimeField(auto_now=True)
	inventory = models.IntegerField()
	alert_limit = models.IntegerField()

class User(models.Model):
	"""用户信息"""
	name = models.CharField(max_length=50)
	password = models.CharField(max_length=50) # md5
	attribute_json = models.CharField(max_length=512)
	ctime = models.DateTimeField(auto_now_add=True)
	mtime = models.DateTimeField(auto_now=True)

class Order(models.Model):
	"""订单信息"""
	user = models.ForeignKey(User)
	product = models.ForeignKey(Product)
	status = models.IntegerField()
	comment = models.TextField()
	ctime = models.DateTimeField(auto_now_add=True)

class ServiceRequest(models.Model):
	"""售后服务请求"""
	user = models.ForeignKey(User)
	status = models.IntegerField()
	title = models.CharField(max_length=1024)
	content = models.TextField()
	ctime = models.DateTimeField(auto_now_add=True)

class ReplyToServiceRequest(models.Model):
	"""售后服务回应"""
	user = models.ForeignKey(User)
	title = models.CharField(max_length=1024)
	content = models.TextField()
	ctime = models.DateTimeField(auto_now_add=True)
	main_serviceRequest = models.ForeignKey(ServiceRequest)

class UserLog(models.Model):
	"""用户访问日志"""
	user = models.ForeignKey(User)
	atime = models.DateTimeField(auto_now_add=True)
	url = models.CharField(max_length=512)
	session = models.ForeignKey(Session)

class Appraisal(models.Model):
	"""评价"""
	user = models.ForeignKey(User)
	product = models.ForeignKey(Product)
	rate = models.IntegerField()
	content = models.TextField()
	ctime = models.DateTimeField(auto_now_add=True)
	mtime = models.DateTimeField(auto_now=True)

class ReplyToAppraisal(models.Model):
	"""评价回复"""
	user = models.ForeignKey(User)
	product = models.ForeignKey(Product)
	rate = models.IntegerField()
	content = models.TextField()
	ctime = models.DateTimeField(auto_now_add=True)
	mtime = models.DateTimeField(auto_now=True)
	main_appraisal = models.ForeignKey(Appraisal)

class Consultation(models.Model):
	"""咨询"""
	user = models.ForeignKey(User)
	title = models.CharField(max_length=1024)
	content = models.TextField()
	ctime = models.DateTimeField(auto_now_add=True)

class ReplyToConsultation(models.Model):
	"""咨询回复"""
	user = models.ForeignKey(User)
	title = models.CharField(max_length=1024)
	content = models.TextField()
	ctime = models.DateTimeField(auto_now_add=True)
	main_consultation = models.ForeignKey(Consultation)

class Transaction(models.Model):
	"""交易记录"""
	user = models.ForeignKey(User)
	order = models.ForeignKey(Order)
	product = models.ForeignKey(Product)
	price = models.CharField(max_length=10)
	atime = models.DateTimeField(auto_now_add=True)
